package com.zzxz.practicaltrainingsys.controller;


import com.zzxz.practicaltrainingsys.entity.ChatMessage;
import com.zzxz.practicaltrainingsys.service.ChatMessageService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/api/chat")
@CrossOrigin(origins = "*")
public class ChatController {

    @Autowired
    private ChatMessageService chatMessageService;

    @GetMapping("/history/{sessionId}")
    public List<ChatMessage> getChatHistory(@PathVariable String sessionId) {
        return chatMessageService.getAllMessages(sessionId);
    }

    @GetMapping("/recent/{sessionId}")
    public List<ChatMessage> getRecentMessages(@PathVariable String sessionId,
                                               @RequestParam(defaultValue = "20") int limit) {
        return chatMessageService.getRecentMessages(sessionId, limit);
    }
}